package com.xd.pre.modules.tpshop.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.xd.pre.modules.tpshop.domain.TpCoupon;
import com.xd.pre.modules.tpshop.domain.TpUsers;
import com.xd.pre.modules.tpshop.mapper.TpUsersMapper;
import com.xd.pre.modules.tpshop.service.ITpUsersService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author lx
 * @since 2020-06-03
 */
@Service
public class TpUsersServiceImpl extends ServiceImpl<TpUsersMapper, TpUsers> implements ITpUsersService {
    @Autowired
    TpUsersMapper usersMapper;

    @Override
    public TpUsers findUser_ById(int user_id) {
        return getById(user_id);
    }

    @Override
    public int update_couponOrBalance(double digital, int user_id) {
        TpUsers oo = new TpUsers();
        Integer payPoints = oo.getPayPoints();
        Double v = Double.parseDouble(payPoints + "") + digital;
        oo.setPayPoints(v.intValue());
        LambdaQueryWrapper<TpUsers> lambdaQuery = Wrappers.lambdaQuery();
        lambdaQuery.eq(TpUsers::getUserId, user_id);
        int update = usersMapper.update(oo, lambdaQuery);
        return update;
    }
}
